{template '_header'}

    <!--<small>订单数: <span class='text-danger'>{php echo intval($total)}</span></small> &nbsp; &nbsp; <small>订单金额: <span class='text-danger'>{php echo number_format($money, 2)}</span></small>-->

<div class="page-header">当前位置：<span class="text-primary">{if !empty($_GPC['inorder'])}【{$_GPC['keyword']}】的{/if}订单管理</span></div>

<div class="page-content">
<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
    <input type="hidden" name="c" value="site" />
    <input type="hidden" name="a" value="entry" />
    <input type="hidden" name="m" value="mx_shop" />
    <input type="hidden" name="do" value="web" />
    <input type="hidden" name="r" value="sorder.order.{$action}" />

    <div class="page-toolbar">
        <div class="col-sm-7">

            <div class="btn-group btn-group-sm" style='float:left'>
                <button class="btn btn-default btn-sm"  type="button" data-toggle='refresh'><i class='fa fa-refresh'></i></button>
            </div>

            <div class='input-group input-group-sm'   >

                <select name="type" class="form-control input-sm select-md" style="width:110px;padding:0 5px;">
                    <option value="" {if $_GPC['paytype']==''}selected{/if}>支付方式</option>
                    {loop $paytype $key $type}
                    <option value="{$key}" {if $_GPC['paytype'] == "$key"} selected="selected" {/if}>{$type['name']}</option>
                    {/loop}
                </select>

                <select name='searchtime'  class='form-control  input-sm select-md'   style="width:110px;padding:0 5px;"  >
                    <option value=''>不按时间</option>
                    <option value='create' {if $_GPC['searchtime']=='create'}selected{/if}>下单时间</option>
                    <option value='pay' {if $_GPC['searchtime']=='pay'}selected{/if}>付款时间</option>
                    <option value='finish' {if $_GPC['searchtime']=='finish'}selected{/if}>完成时间</option>
                </select>

                {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d H:i', $endtime)),true);}

            </div>
        </div>

        <div class="col-sm-5 pull-right">
            <div class="input-group">
            <div class="input-group-select">
                <select name='searchfield' class='form-control  input-sm select-md' style="width:110px;"  >
                    <option value="ordersn" {if $_GPC['searchfield']=='order'}selected{/if}>订单号</option>
                    <option value="member" {if $_GPC['searchfield']=='member'}selected{/if}>会员信息</option>
                    <option value="goods" {if $_GPC['searchfield']=='goods'}selected{/if}>设备名称</option>
                    <option value="mendian" {if $_GPC['searchfield']=='mendian'}selected{/if}>门店名称</option>
                </select>
            </div>

                <input type="text" class="form-control input-sm"  name="keyword" value="{$_GPC['keyword']}" placeholder="请输入关键词"/>

                <span class="input-group-btn">
                    <button class="btn btn-sm btn-primary" type="submit"> 搜索</button>
                </span>

            </div>
        </div>
    </div>
</form>
{if !empty($list)}

<table class="table table-hover table-responsive">
    <thead class="navbar-inner" >
    <tr style='background:#f8f8f8'>
        <td style='width:60px;border-left:1px solid #f2f2f2;'>商品</td>
        <td style='width:150px;'></td>
        <td style='width:70px;text-align: right;;'>单价</td>
        <td  style='width:100px;text-align: center;'>买家</td>
        <td style='width:90px;text-align: center;'>支付</td>
        <td style='width:100px;text-align: center;'>价格</td>
        <td style='width:100px;text-align: center;'>下单时间</td>
        <td style='width:90px;text-align: center'>状态</td>
    </tr>
    </thead>
    <tbody>
    {loop $list $item}

    <tr ><td colspan='8' style='height:20px;padding:0;border-top:none;'>&nbsp;</td></tr>

    <tr class='trorder'>
        <td colspan='4' >
            订单编号:  {$item['ordersn']}
        </td>
        <td colspan='4' style='text-align:right;font-size:12px;' class='aops'>
            {ifp 'sorder.order.close'}
            {if $item['status'] == 1} <a class='op'  href="{php echo webUrl('sorder/order_op/close', array('id' => $item['id']))}" data-toggle="ajaxPost" data-confirm="确认要关闭此订单吗？">关闭订单</a> - {/if}
            {/if}
            {ifp 'sorder.order.view'}
            <a class='op' style="margin-right: 20px" href="{php echo webUrl('sorder/order/detail', array('id' => $item['id']))}" >查看详情</a>
            {/if}
        </td>
    </tr>

    <tr class='trbody'>
            <td><img src="{php echo tomedia($item['thumb'])}" style='width:50px;height:50px;border:1px solid #ccc; padding:1px;'></td>
            <td>{$item['goods_name']}</td>
            <td>{$item['goodsprice']}</td>
            <td style="text-align: center;">{$item['realname']}</td>
            <td style="text-align: center;">{$paytype[$item['paytype']]['name']}</td>
            <td style="text-align: center;">{$item['realprice']}</td>
            <td style="text-align: center;">{php echo date('Y-m-d',$item['createtime'])}<br/>{php echo date('H:i:s',$item['createtime'])}</td>
        <td class='ops' style='line-height:20px;text-align:center' >
            <span class='text-{$orderstatus[$item['status']]['css']}'>{$orderstatus[$item['status']]['name']}</span><br />{template 'sorder/order/ops'}
        </td>
    </tr>
    <tr style=";border-bottom:none;background:#f9f9f9;">
        <td colspan="8" style="text-align:left">
            {if empty($item['opentime'])}
                <span class="btn btn-default btn-xs">未开启</span>
            {else}
                {if $item['status'] == 2 && (($item['usetime'] * 60) + $item['opentime']) > time()}
                    <span class="btn btn-warning btn-xs">使用中</span>
                {else}
                    <span class="btn btn-primary btn-xs">已完成</span>
                {/if}

                设备开启时间： {php echo date('Y-m-d H:i:s', $item['opentime'])} &nbsp; &nbsp;
                设备结束时间： {php echo date('Y-m-d H:i:s', ($item['opentime'] + ($item['usetime'] * 60)))} &nbsp; &nbsp;
                {if $item['status'] == 2}
                    设备自动关闭时间约有一分钟的误差
                {/if}
            {/if}



        </td>
    </tr>
    {if ($item['status'] == 5) || ($item['status'] == 6)}
    <tr ><td colspan='8' style='background:#fdeeee;color:red;'>退款原因: {$item['reason']} &nbsp; &nbsp; 退款留言：{$item['content']}</td></tr>
    {/if}
    {/loop}
    </tbody>
</table>

{$pager}

    {else}
    <div class="panel panel-default">
        <div class="panel-body empty-data">未查询到相关数据</div>
    </div>
    {/if}
</div>

<script language="javascript">

    $('.daterange').attr('class','btn btn-default daterange daterange-time btn-sm');
    require(['bootstrap'],function(){
        $("[rel=pop]").popover({
            trigger:'manual',
            placement : 'left',
            title : $(this).data('title'),
            html: 'true',
            content : $(this).data('content'),
            animation: false
        }).on("mouseenter", function () {
            var _this = this;
            $(this).popover("show");
            $(this).siblings(".popover").on("mouseleave", function () {
                $(_this).popover('hide');
            });
        }).on("mouseleave", function () {
            var _this = this;
            setTimeout(function () {
                if (!$(".popover:hover").length) {
                    $(_this).popover("hide")
                }
            }, 100);
        });
    });

</script>

{template '_footer'}